import type { PostLoginData } from '@/types/common'
import { defineStore } from 'pinia'
import { ref } from 'vue'

export const useUserStore = defineStore('userStore', () => {
  const token = ref('')

  const setToken = (val: string) => {
    token.value = val
  }
  const getToken = () => {
    return token.value
  }
  const clearToken = () => {
    token.value = ''
  }
  const userInfo = ref<PostLoginData>()
  const setUserInfo = (val: PostLoginData) => {
    userInfo.value = val
  }
  const getUserInfo = () => {
    return userInfo.value
  }
  const clearUserInfo = () => {
    userInfo.value = undefined
  }
  return {
    token,
    setToken,
    getToken,
    clearToken,
    userInfo,
    setUserInfo,
    getUserInfo,
    clearUserInfo,
  }
},{
  persist:true
})
